<?php
class NewBudget_Message{
	private static $rssDoc="../db/message.xml";
	private static $rssNum=20;
	public static $rss;
	private static function cleanDoc(){//如果消息超过规定条数，刚删除一条消息
		$rssNode=self::$rss->xselect("channel")->item(0);
		$items=$items=self::$rss->xselect("channel/item");
		if($items->length>self::$rssNum)
			$rssNode->removeChild($items->item(0));
	}
	private static function makeItemNode($node,$value){
		$node=self::$rss->doc->createElement($node);
		$node->appendChild(self::$rss->doc->createTextNode($value));
		return $node;
	}
	private static function makeMessageNode($title,$author,$description){
		$newNode=self::$rss->doc->createElement("item");
		$newNode->appendChild(self::makeItemNode("title",$title));
		$newNode->appendChild(self::makeItemNode("author",$author));
		$newNode->appendChild(self::makeItemNode("description",$description));
		$newNode->appendChild(self::makeItemNode("pubdate",date("Y-m-d H:i:s")));
		return $newNode;
	}
	public static function newMessage($title,$author,$description){
		self::$rss=new NewBudget_XmlDb(self::$rssDoc);
		$rssNode=self::$rss->xselect("channel")->item(0);
		$rssNode->appendChild(self::makeMessageNode($title,$author,$description));
		self::cleanDoc();
		self::$rss->saveDoc();
	}
}
function newMessage($title,$description){
	NewBudget_Message::newMessage($title,NewBudget_Session::get("username"),$description);
}
?>